package com.zbkj.dal.base.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

/**
 * 供享（RecycleType）类型
 */
@Getter
@AllArgsConstructor
public enum BizShareModeEnum {
    // 保价
    SUPPORT_VALUE("SUPPORT_VALUE", "保价模式"),
    // 非保价
    UN_SUPPORT_VALUE("UN_SUPPORT_VALUE", "非保价模式");

    private final String code;

    private final String desc;

    /**
     * 是否是保价
     *
     * @param code
     * @return
     */
    public static boolean isVal(String code) {
        return ObjectUtils.nullSafeEquals(code, BizShareModeEnum.SUPPORT_VALUE.getCode());
    }

    /**
     * 非保价
     *
     * @param type
     * @return
     */
    public static boolean isNv(String type) {
        return ObjectUtils.nullSafeEquals(type, BizShareModeEnum.UN_SUPPORT_VALUE.getCode());
    }

    public static String toName(String code) {
        if (StringUtils.isEmpty(code)) {
            return StringUtils.EMPTY;
        }
        for (BizShareModeEnum value : BizShareModeEnum.values()) {
            if (StringUtils.equals(value.getCode(), code)) {
                return value.getDesc();
            }
        }
        return StringUtils.EMPTY;
    }
}
